<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2023-03-10
 * Time: 16:32:00
 * Info:
 */

namespace app\common\model;

class SystemLog extends TimeInit
{

    public static function getLogList($params = [])
    {
        $limit = $params['limit'] ?? 10;
        $page  = $params['page'] ?? 1;
        $key   = $params['key'] ?? '';
        $first = ($page - 1) * $limit;

        $where = function ($query) use ($key) {
            if ( ! empty($key['user_name'])) {
                $query->where('user_name', $key['user_name']);
            }
        };
        $count = self::where($where)->count();
        $list  = self::where($where)->limit($first, $limit)->order("id desc")->select()->toArray();
        foreach ($list as $k => $v) {
            /*$list[$k]['address']    = $v['country'].' '.$v['area'].' '.$v['city'].' '.$v['isp'];
            $list[$k]['os_vv']      = $v['os'].' '.$v['os_ver'];
            $list[$k]['browser_vv'] = $v['browser'].' '.$v['browser_ver'];*/
        }

        $data['list']  = $list ?? [];
        $data['count'] = $count ?? [];

        return $data;
    }

    public static function addData($param)
    {
        try {
            self::create($param);
        } catch (\Exception $e) {

        }

    }

}
